<template>
  <div>
    <el-row :gutter="10" style="margin-bottom: 40px">
      <el-col :span="6">
        <el-card style="color: #409EFF">
          <div slot="header" class="clearfix">
            <span><i class="el-icon-user-solid"></i> 总用户数</span>
          </div>
          <div>
            {{ totalUser }}
          </div>
        </el-card>

      </el-col>
      <el-col :span="6">
        <el-card style="color: #67C23A">
          <div slot="header" class="clearfix">
            <span>销售总量</span>
          </div>
          <div>
            100
          </div>
        </el-card>
      </el-col>
      <el-col :span="6">
        <el-card style="color: #E6A23C">
          <div slot="header" class="clearfix">
            <span>销售收益</span>
          </div>
          <div>
            100
          </div>
        </el-card>
      </el-col>
      <el-col :span="6">
        <el-card style="color: #909399">
          <div slot="header" class="clearfix">
            <span>门店数量</span>
          </div>
          <div>
            100
          </div>
        </el-card>
      </el-col>
    </el-row>

    <br>

    <el-row>
      <el-col :span="12">
        <div id="main" style="width: 500px;height: 500px"></div>
      </el-col>

      <el-col :span="12">
        <div id="pie" style="width: 500px;height: 500px;"></div>
      </el-col>
    </el-row>

  </div>
</template>

<script>
import * as echarts from 'echarts';


export default {
  name: "Home",
  data() {
    return {
      totalUser: [],
    }

  },
  created() {
    this.load();
  },
  methods: {
    //获取用户数量
    load() {
      this.request.get('/echarts/allMembers').then(res => {
        this.totalUser = res.data
      }).catch(err => {
        console.log(err);
      });
    },
  },

  mounted() {//页面加载完成后执行

    // 指定图表的配置项和数据 折线图和柱状图
    var option = {
      title: {
        text: '各个季度的注册人数',
        subtext: '趋势图',
        left: 'center'
      },
      tooltip: {},
      xAxis: {
        type: 'category',
        data: ["第一季度", "第二季度", "第三季度", "第四季度"]
      },
      yAxis: {
        type: 'value'
      },
      series: [
        {
          data: [],
          type: 'line'
        },
        {
          data: [],
          type: 'bar'
        }
      ]
    };


    //饼图
    var pieOption = {
      title: {
        text: '各个季度会员数量比例图',
        subtext: '百分比',
        left: 'center'
      },
      tooltip: {
        trigger: 'item'
      },
      legend: {
        orient: 'vertical',
        left: 'left'
      },
      series: [
        {
          type: 'pie',
          radius: '50%',
          label: {
            show: true,
            formatter: '{b}:{c}({d}%)',

          },
          data: [],//数据填空
          emphasis: {
            itemStyle: {
              shadowBlur: 10,
              shadowOffsetX: 0,
              shadowColor: 'rgba(0, 0, 0, 0.5)'
            }
          }
        }
      ]
    };

    //折线图
    // 基于准备好的dom，初始化echarts实例
    var chartDom = document.getElementById('main');
    var myChart = echarts.init(chartDom);
    //饼图
    //基于准备好的dom，初始化echarts实例
    var pieDom = document.getElementById('pie');
    var pieChart = echarts.init(pieDom);
    // 使用刚指定的配置项和数据显示图表。
    this.request.get("/echarts/members").then(res => {
      //折线图数据
      //option.xAxis.data = res.data.x;
      option.series[0].data = res.data
      option.series[1].data = res.data
      //数据准备完毕后再渲染图表
      myChart.setOption(option);//设置option

      //饼图数据
      pieOption.series[0].data = [
        {name: "第一季度", value: res.data[0]},
        {name: "第二季度", value: res.data[1]},
        {name: "第三季度", value: res.data[2]},
        {name: "第四季度", value: res.data[3]},
      ]
      //数据准备完毕后再渲染图表
      pieChart.setOption(pieOption);//设置饼图

    });


  },

}
</script>

<style scoped>

</style>